package com.bdqn.spark.chapter05.kv

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

object Spark23_RDD_Operator_Transform {
  def main(args: Array[String]): Unit = {
    val sparkConf = new SparkConf()
      .setMaster("local[*]")
      .setAppName("operator-sortByKey")
    val sc = new SparkContext(sparkConf)

    val rdd: RDD[(String, Int)] = sc.makeRDD(
      List(
        ("a", 1),
        ("b", 2),
        ("c", 3)
      )
    )

    //    val resultRDD: RDD[(String, Int)] = rdd.sortByKey()
    //    val resultRDD: RDD[(String, Int)] = rdd.sortByKey(false)
    val resultRDD: RDD[(String, Int)] = rdd.sortBy(_._1)
    resultRDD.collect().foreach(println)

    sc.stop()
  }
}
